<?php
require_once('../lib/standard.php');
$pineza = new Globals();
if (session_set('admin')) {
	admin_menu();
}
else if (is_array($_POST) && array_key_exists('kodikos', $_POST)) {
	if (sha1($_POST['kodikos']) == $pineza->admpass) {
		$_SESSION['admin'] = TRUE;
		admin_menu();
	}
	else {
		admin_login('Access denied');
	}
}
else {
	admin_login();
}
telos_selidas();

function admin_login($msg = FALSE) {
	global $pineza;
	?>
	<link rel="stylesheet" type="text/css" href="<?php print $pineza->server; ?>admin/adminLogin.css" />
	<script type="text/javascript" src="<?php print $pineza->server; ?>admin/adminLogin.js"></script>
	<?php arxi_selidas(); ?>
	<?php
	if ($msg) {
		?>
		<div class="main" style="margin-top: 1.0em; margin-bottom: -2.0em;">
			<?php lathos($msg); ?>
		</div>
		<?php
	}
	?>
	<form method="post" class="main" action="<?php print $pineza->server; ?>admin/index.php">
	<table class="forma">
	<tr>
	<td class="tbldbg" colspan="10">
		<div class="formaHeader">
			<span class="formaHeaderText">
				<?php print "Administrator's Login"; ?>
			</span>
		</div>
	</td>
	</tr>

	<tr>
	<td class="protropi tbldbg">
		Password
	</td>
	<td class="tbldbg">
		<input id="kodikos" type="password" name="kodikos" value="" maxlength="40"
			size="20" class="pedio" />
	</td>
	</tr>
	</table>
	<input type="submit" value="Login" class="fButton" />
	<input type="submit" value="Reset" class="fButton" onclick="return(resetAdmin(this.form));" />
	<input type="submit" value="Cancel" class="fButton" onclick="return(cancelAdmin(this.form));" />
	</form>
	</table>
	<?php
}

function admin_menu() {
	global $pineza;
	?>
	<link rel="stylesheet" type="text/css" href="<?php print $pineza->server; ?>admin/admin.css" />
	<script type="text/javascript" src="<?php print $pineza->server; ?>admin/admin.js"></script>
	<?php arxi_selidas(); ?>
	<div class="main">
	<div class="header">
		Administrator Menu
	</div>
	<table>
	<?php
	menu_item('Create database', 'createdb',
		'All data will be erased! Please confirm or abort.');
	menu_item('Backup Database', 'budb',
		'Database backup may last for several minutes. Please confirm or abort.');
	menu_item('Restore Database', 'redb',
		'All data will be erased! Please confirm or abort.');
	menu_item('Exit Administrator');
	?>
	</table>
	</div>
	<?php
}

function menu_item($desc, $func = '', $warn = '') {
	global $pineza;
	?>
	<tr>
	<td>
		<div class="menuItem" onclick="return doTheJob('<?php
			print $func; ?>', this, '<?php print $warn; ?>');"
			onmouseover="megaloma(this);" onmouseout="mikrema(this);">
			<?php print $desc; ?>
		</div>
	</td>
	<td>
		<img id="<?php print $func; ?>Icon" class="workingIcon" alt="working icon" src="<?php
			print $pineza->server; ?>images/working.gif" />
	</td>
	</tr>
	<?php
}
?>
